<?php
require_once 'tools/db/DbUtils.php';

function getQueryForKey($queryKey,$course){
	$query=null;
	switch($queryKey){
		case "general":
			$query="SELECT
						res.id as resultId,
						team.dossard,
						res.temp,
						sub.course_key,
						run1.nom as nom1,
						run1.prenom as prenom1,
						run1.sexe as sexe1,
						run2.sexe as sexe2,
						run2.nom as nom2,
						run2.prenom as prenom2 
						
					FROM resultats res 
						join runner run1 on res.fk_runner1=run1.id
						join runner run2 on res.fk_runner2=run2.id
						join equipe team on res.fk_team=team.id 
						join equipe_subscribed sub on team.id=sub.fk_team
						where sub.course_key='".$course."'
						and res.course_key='".$course."'
					ORDER by res.temp";
			break;
			case "generalLast10":
			$query="SELECT
						team.dossard,
						res.temp,
						sub.course_key,
						run1.nom as nom1,
						run1.prenom as prenom1,
						run1.sexe as sexe1,
						run2.sexe as sexe2,
						run2.nom as nom2,
						run2.prenom as prenom2 
						
					FROM resultats res 
						join runner run1 on res.fk_runner1=run1.id
						join runner run2 on res.fk_runner2=run2.id
						join equipe team on res.fk_team=team.id 
						join equipe_subscribed sub on team.id=sub.fk_team
						where sub.course_key='".$course."'
						and res.course_key='".$course."'
					ORDER  by res.temp DESC LIMIT 10";
			break;
		case "challenge":
			$query="SELECT
	*
      
FROM equipe team 
	join equipe_subscribed sub on team.id=sub.fk_team
        join runner run1 on team.fk_first_runner=run1.id
join runner run2 on team.fk_second_runner=run2.id";
			break;
		case "results":
		default:
			$query="SELECT
						res.id as resultId,
						team.dossard,
						res.temp,
						sub.course_key,
						run1.nom as nom1,
						run1.prenom as prenom1,
						run1.sexe as sexe1,
						run2.sexe as sexe2,
						run2.nom as nom2,
						run2.prenom as prenom2 
					FROM resultats res 
						join runner run1 on res.fk_runner1=run1.id
						join runner run2 on res.fk_runner2=run2.id
						join equipe team on res.fk_team=team.id 
						join equipe_subscribed sub on team.id=sub.fk_team
						where sub.course_key='".$course."'
						and res.course_key='".$course."'
					ORDER by res.temp";
			break;

	}
	return $query;

}
?>